<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
	<link rel="stylesheet" type="text/css" href="/css/base.css">
	<link rel="stylesheet" type="text/css" href="/css/editpassword.css">
</head>
<script src="/js/jquery-3.1.1.min.js"></script>
 <script src="/js/layer/layer.js"></script>
<body>
	<div class="indexAll">
		<div class="titleWrap">
			<span class="title">修改密码</span>
		</div>
		<div class="mainWrap">
			<div class="main">
				<div class="contentWrap">
					<div class="newpass">
						<span class="passtitle">原密码：&nbsp;&nbsp;&nbsp; </span>
						<input type="password" name="password" class="oldpassinfo passinfo" placeholder="请输入原始密码">
					</div>
					<div class="newpass">
						<span class="passtitle">新密码：&nbsp;&nbsp;&nbsp; </span>
						<input type="password" name="password" class="newpassinfo passinfo" placeholder="请输入6-18位新密码">
					</div>
					<div class="oldpass">
						<span class="passtitle">重新输入：</span>
						<input type="password" name="password" class="repassinfo passinfo" placeholder="请再次输入新密码">
					</div>
					<div class="primaryBtn">
						<span class="determineBtn">确定</span>
					</div>					
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$('.primaryBtn').click(function(){
		var oldpass = $('.oldpassinfo').val();
		var newpass = $('.newpassinfo').val();
		var repass = $('.repassinfo').val();
		var reg = /^[a-zA-Z0-9]{6,18}$/;
		if (oldpass=='') {
			layer.tips('原密码不能为空', '.oldpassinfo');
            return false;
		}else if (newpass=='') {
			layer.tips('密码不能为空', '.newpassinfo');
            return false;
		}else if (!reg.test(newpass)) {
			layer.tips('密码格式不正确', '.newpassinfo');
            return false;
		}else if (repass == '') {
			layer.tips('请再次输入密码', '.repassinfo');
            return false;
		}else if (newpass != repass) {
			layer.tips('两次输入的密码不一致', '.repassinfo');
            return false;
		}else{
			$.ajax({
                type:'POST',
                url:'/index/Personalcenter/doeditpassword',
                data: {'oldpass':oldpass,'password':newpass},
                dataType:'json',
                success:function (data) {
                    console.log(data)
                    if(data==1){
                       layer.msg('修改成功！', {
                        icon: 1,
                        time: 1000
                    	}, function () {
                       	 	window.location.href = "/index/index/login";
                    	});
                    }else{
                    	layer.msg(data.msg, {
                        icon: 2,
                        time: 1000
                    }, function () {
                        	
                   		});
                    }
                },
                error:function (errorData) {
                    layer.alert('修改失败！', {icon: 2}, function () {
                    layer.closeAll();
                	})
                }
            })
		}
	})
</script>
</html>